﻿using SimpleESBCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace SimpleESBCore.Implement
{
    public class MessageService : IMessageService
    {
        public bool SendMessage(Socket socket,string message)
        {
            if (socket.Connected)
            {
                byte[] buffer = Encoding.Unicode.GetBytes(message);
                try
                {
                    socket.Send(buffer);
                    return true;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                throw new Exception("已断开与远程主机的连接!");
            }
        }
    }
}
